package models;

import play.*;
import play.db.jpa.*;
import javax.persistence.*;

import java.util.*;

@Entity
@Table(name = "tutorial_reviews")
public class Review extends Model {

	/**
	 * Attributes of Reviews
	 * 
	 * @author Mahmoud
	 **/
	long userId;
	long tutId;
	@Lob
	public String review;
	public boolean isReplied;
	public boolean readyToPublish;
	public boolean creatorAccept;

	/*** Dina Medhat ***/
	@OneToMany(mappedBy = "reviewReplies", cascade = CascadeType.ALL)
	public List<Reply> replyList;

	// @OneToMany(mappedBy="advice", cascade=CascadeType.ALL)

	// @OneToMany//(mappedBy="advice", cascade=CascadeType.ALL)

	/**
	 * Reviews Initializer Constructor
	 * 
	 * @author Mahmoud
	 **/
	public Review(long userId, long tutId, String review) {

		this.userId = userId;
		this.review = review;
		this.tutId = tutId;
		this.readyToPublish = false;

	}

	public Review() {

	}

	/**
	 * This method gets the userId
	 * 
	 * @author Mahmoud
	 */
	public long getUserId() {
		return userId;
	}

	/**
	 * This method sets the userId
	 * 
	 * @author Mahmoud
	 * @param userId
	 */
	public void setUserId(long userId) {
		this.userId = userId;
	}

	/**
	 * This method gets the tutId
	 * 
	 * @author Mahmoud
	 */
	public long getTutId() {
		return tutId;
	}

	/**
	 * This method sets the tutId
	 * 
	 * @author Mahmoud
	 * @param tutId
	 */
	public void setTutId(long tutId) {
		this.tutId = tutId;
	}

	/**
	 * This method gets the Review
	 * 
	 * @author Mahmoud
	 */
	public String getReview() {
		return review;
	}

	/**
	 * This method sets the Review
	 * 
	 * @author Mahmoud
	 * @param review
	 */
	public void setReview(String review) {
		this.review = review;
	}

	/**
	 * This method gets the isReplied with true when there is a reply created.
	 * 
	 * @author Dina
	 * */
	public boolean isReplied() {
		return isReplied;
	}

	public void setReplied(boolean isReplied) {
		this.isReplied = isReplied;
	}

	/**
	 * This method gets the readyToPublish true if the reviewer clicked on the
	 * accept button in the review.
	 * 
	 * @author Dina
	 * */
	public boolean isReadyToPublish() {
		return readyToPublish;
	}

	/**
	 * This method sets the value of readyToPublish to notify the creator of the
	 * tutorial that his/her tutorial is ready to be published
	 * 
	 * @author Dina
	 * */
	public void setReadyToPublish(boolean readyToPublish) {
		Tutorial tutorial = Tutorial.findById(this.getTutId());
		this.readyToPublish = readyToPublish;
		tutorial.setReady(readyToPublish);
		tutorial.save();
	}

	/**
	 * This method gets the value of readyToPublish to notify the creator of the
	 * tutorial that his/her tutorial is ready to be published
	 * 
	 * @author Dina
	 * */
	public boolean isCreatorAccept() {
		return creatorAccept;
	}

	/**
	 * This method set the creatorAccept true if the creator/contributor clicked
	 * on the accept button in the review.
	 * 
	 * @author Dina
	 * */
	public void setCreatorAccept(boolean creatorAccept) {
		this.creatorAccept = creatorAccept;
	}

	public List<Reply> getReplyList() {
		return replyList;
	}

	public void setReplyList(List<Reply> replyList) {
		this.replyList = replyList;
	}
}
